***ANALYSIS FILE FOR JEPP R&R*** 


cd "/Users/stuartturnbulldugarte/OneDrive - University of Southampton/KCL_WIPs/Pink Vote/ESS"
use ESS_analysisfile.dta, clear

cd "/Users/stuartturnbulldugarte/OneDrive - University of Southampton/KCL_WIPs/MD Lavender/RR/New_analysis"


merge m:1 cntryID year using oecd_clean.dta 

rename _merge merge_oecd

merge m:1 cntryID essround using cmp_datamerge.dta



gen election=cntryID*year

rename imsmetn immsame
replace immsame=. if immsame>4

rename imdfetn immdiff
replace immdiff=. if immdif>4

rename impcntr immpoor
replace immpoor=. if immpoor>4

rename imueclt immcul
replace immcul=. if immcul>10

gen immculdum=.
replace immculdum=0 if immcul<=5
replace immculdum=1 if immcul>5

gen euviewdum=.
replace euviewdum=0 if euview<=5
replace euviewdum=1 if euview>5

gen immdum=.
replace immdum=0 if immigrationview<=5
replace immdum=1 if immigrationview>5

gen incomenew=income1 if income2==.
replace incomenew=income2 if income2!=.
replace incomenew=. if incomenew>10

rename mnactic empstat
replace empstat=. if empstat>60
gen employ=.
replace employ=1 if empstat==1
replace employ=2 if empstat==3
replace employ=3 if empstat==2
replace employ=4 if empstat==4
replace employ=4 if empstat==5
replace employ=4 if empstat==7
replace employ=4 if empstat==8
replace employ=4 if empstat==9
replace employ=5 if empstat==6

label var employ "Employment status"
label define EMPLOY 1"Working" 2"Job-seeker" 3"Studying" 4"NIWF" 5"Retired"
label value employ EMPLOY

gen struggling=.
replace struggling=0 if swi>=3
replace struggling=1 if swi<3

gen parents=.
replace parents=moth_nonnativ+fath_nonnativ

gen agesq=agea*agea

gen postmigrant=0
replace postmigrant=1 if year>2015

***Advanced indicators and models of immigration***
gen poordum=.
replace poordum=1 if immpoor==4
replace poordum=0 if immpoor<4

gen diffdum=.
replace diffdum=1 if immdiff==4
replace diffdum=0 if immdiff<4

gen samedum=.
replace samedum=1 if immsame==4
replace samedum=0 if immsame<4

***TABLE 1***


**EU MODELS
reg euview GL gender agea agesq i.education i.employ incomenew i.parents i.cntryID i.year if fulldata==1 & partner==1 & cntryID!=4 & cntryID!=24 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) replace drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)

reg  euview GL gender agea agesq i.education i.employ incomenew i.parents econview swd i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 & cntryID!=4 & cntryID!=24 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)

reg  euview GL gender agea agesq i.education i.employ incomenew i.parents econview swd i.struggling c.lrscale c.religious c.assylog_lag i.cntryID i.year if fulldata==1 & partner==1 & cntryID!=4 & cntryID!=24 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)

reg  euview GL gender agea agesq i.education i.employ incomenew i.parents econview swd i.struggling c.lrscale c.religious c.country_euview i.cntryID i.year if fulldata==1 & partner==1 & cntryID!=4 & cntryID!=24 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)


**Imm1 models
reg  immigrationview GL gender agea agesq i.education i.employ incomenew i.parents i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)

reg  immigrationview GL gender agea agesq i.education i.employ incomenew i.parents econview swd i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)

reg  immigrationview GL gender agea agesq i.education i.employ incomenew i.parents econview swd i.struggling c.lrscale c.religious c.assylog_lag i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)

reg  immigrationview GL gender agea agesq i.education i.employ incomenew i.parents econview swd i.struggling c.lrscale c.religious c.country_mulcul i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)


**Imm2 models
reg  immcul GL gender agea agesq i.education i.employ incomenew i.parents i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)

reg immcul GL gender agea agesq i.education i.employ incomenew i.parents econview swd i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)

reg immcul GL gender agea agesq i.education i.employ incomenew i.parents econview swd i.struggling c.lrscale c.religious c.assylog_lag i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)

reg  immcul GL gender agea agesq i.education i.employ incomenew i.parents econview swd i.struggling c.lrscale c.religious c.country_mulcul i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
outreg2 using table1_RR_ordinal2.doc, dec(2) append drop(i.cntryID i.year) addtext(Country FE, Yes, Year FE, Yes)



***Figure 1***

reg euview GL gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 & cntryID!=4 & cntryID!=24 [pw=weight], robust cluster(cntry)
margins, dydx(*) post
estimates store eu_m1

reg immigrationview GL gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious c.assylog_lag i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(*) post
estimates store imm_m1

reg immcul GL gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious c.assylog_lag i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(*) post
estimates store immc_m1


logit euviewdum GL gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(*) post
estimates store eu_m2


logit immdum GL gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(*) post
estimates store imm_m2


logit immculdum GL gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(*) post
estimates store immcul_m2


coefplot eu_m1 || imm_m1|| immc_m1, keep(GL) xline(0, lpattern(dash) lcolor(navy)) ci(95 90) byopts(col(1)) xlabel(-.2(.2).6) xscale(range(-.2(.2).6)) mlabel format(%9.2g) mlabposition(2) mlabgap(*2) msymbol(circle) msize(medium) mlabcolor(pink) mcolor(pink) ciopts(recast(. rcap) color(pink))
graph save plot1.gph , replace

coefplot eu_m2 || imm_m2|| immcul_m2, keep(GL) xline(0, lpattern(dash) lcolor(navy)) ci(95 90) rescale(100) byopts(col(1)) xlabel(-2(2)8) xscale(range(-.2(.2).8)) mlabel format(%9.2g) mlabposition(2) mlabgap(*2) mlabcolor(pink) msymbol(circle) msize(medium) mcolor(pink) ciopts(recast(. rcap) color(pink))
graph save plot2.gph , replace

graph combine plot1.gph plot2.gph, row(1)



***FIGURE 2***
reg euview i.GL##c.incomenew gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 & cntryID!=4 & cntryID!=24 [pw=weight], robust cluster(cntry)
margins, dydx(GL) at(incomenew=(1(1)10))
marginsplot, yline(0) addplot(histogram incomenew if e(sample), discrete percent yaxis(2) yscale(alt) fcolor(%10) lc(navy%30))

graph save marg4.gph, replace

reg immigrationview i.GL##c.incomenew gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(GL) at(incomenew=(1(1)10))
marginsplot, yline(0) addplot(histogram incomenew if e(sample), discrete percent yaxis(2) yscale(alt) fcolor(%10) lc(navy%30))

graph save marg5.gph, replace

reg immcul i.GL##c.incomenew gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(GL) at(incomenew=(1(1)10))
marginsplot, yline(0) addplot(histogram incomenew if e(sample), discrete percent yaxis(2) yscale(alt) fcolor(%10) lc(navy%30))

graph save marg6.gph, replace

graph combine marg4.gph marg5.gph marg6.gph, xcommon ycommon col(1)





***Figure 3***

logit poordum GL gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(*) post
estimates store poorm1

logit diffdum GL gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(*) post
estimates store diffm1

logit samedum GL gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(*) post
estimates store samem1


coefplot poorm1|| diffm1 || samem1, keep(GL) vertical yline(0, lpattern(dash) lcolor(navy)) rescale(100) ylabel(-6(2)2) yscale(range(-6(2)2)) ci(95 90) byopts(row(1)) mlabel format(%9.2g) mlabposition(2) mlabgap(*2) mlabcolor(midgreen) msymbol(circle) msize(medium) mcolor(midgreen) ciopts(recast(. rcap) color(midgreen))





***Estimating conditional effect on income: FIGURE 4***

logit poordum i.GL##c.incomenew gender agea i.employ i.education econview swd i.parents i.struggling c.lrscale c.religious assylog_lag i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(GL) at(incomenew=(1(1)10))
marginsplot, yline(0, lpattern(dash) lcolor(midblue)) addplot(histogram incomenew if e(sample), discrete percent yaxis(2) yscale(alt) fcolor(%10) lc(navy%30))

logit diffdum i.GL##c.incomenew gender agea i.employ i.education econview swd i.parents i.struggling c.lrscale c.religious assylog_lag i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(GL) at(incomenew=(1(1)10))
marginsplot, yline(0, lpattern(dash) lcolor(midblue)) addplot(histogram incomenew if e(sample), discrete percent yaxis(2) yscale(alt) fcolor(%10) lc(navy%30))

logit samedum i.GL##c.incomenew gender agea i.employ i.education econview swd i.parents i.struggling c.lrscale c.religious assylog_lag i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(GL) at(incomenew=(1(1)10))
marginsplot, yline(0, lpattern(dash) lcolor(midblue)) addplot(histogram incomenew if e(sample), discrete percent yaxis(2) yscale(alt) fcolor(%10) lc(navy%30))


graph combine RR_Figure4.gph RR_Figure5.gph RR_Figure6.gph, xcommon ycommon col(1)



//FIGURE 5***

logit diffdum GL##c.assylog_lag gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(GL) at(assylog_lag=(4.5(.5)13))
marginsplot, l(90) xlabel(4(2)14) xscale(range(4(.5)14)) yline(0, lpattern(dash) lcolor(navy)) addplot(hist assylog_lag if e(sample), blcolor(midgreen) fcolor(midgreen) discrete percent yaxis(2) yscale(alt lcolor() axis(2)) ylabel(0 " " 20 " " 40 " " 60 " " 80 " " 100 " ", labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small) tl(0)) ytitle(" ", axis(2)))
graph save assy_interact.gph, replace



logit diffdum GL##c.country_mulcul gender agea agesq i.education i.employ incomenew econview swd i.parents i.struggling c.lrscale c.religious i.cntryID i.year if fulldata==1 & partner==1 [pw=weight], robust cluster(cntry)
margins, dydx(GL) at(country_mulcul=(-.14(.02).24))
marginsplot, l(90) xlabel(-.14(.02).24) xscale(range(-.15(.05).25)) yline(0, lpattern(dash) lcolor(navy)) addplot(hist country_mulcul if e(sample), blcolor(pink) fcolor(pink) discrete percent yaxis(2) yscale(alt lcolor() axis(2)) ylabel(0 " " 20 " " 40 " " 60 " " 80 " " 100 " ", labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small) tl(0)) ytitle(" ", axis(2)))
graph save fig_sysinteract.gph, replace

graph combine assy_interact.gph fig_sysinteract.gph, row(1)




